package com.jiot.controller.device;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.kit.Ret;
import com.jiot.common.model.dto.DeviceThresholdDTO;
import com.jiot.controller.BaseController;

import io.swagger.annotations.ApiModelProperty;

/**
 * 设备相关
 * 
 * 项目 --> 场景 --> 设备
 * @author zy
 *
 */

@Before({})
public class DeviceController extends BaseController {

    @Inject
    DeviceService deviceService;

    @Inject
    DeviceLogService deviceLogService;

    @Inject
    DeviceAlarmLogService deviceAlarmLogService;

    
    /**
     * 通过项目id分页查询所有设备
     * @param selectDeviceAllReq
     * @return
     */
    public void selectPageByProjectId(Integer projectId, Integer pageNumber) {
    	Ret ret = deviceService.selectPageByProjectId(getAttr("user"), projectId, pageNumber);
    	renderJson(ret);
    }

    /**
     * 通过设备id查看设备信息
     */
    public void detailById(Integer deviceId) {
    	Ret ret = deviceService.selectByDeviceId(getAttr("user"), deviceId);
    	renderJson(ret);
    }
    
    /**
     * 用户绑定设备
     */
    public void bindingDevice(Integer deviceId,Integer projectId,Integer sceneId) {
    	Ret ret = deviceService.bindingDevice(getAttr("user"), deviceId, projectId, sceneId);
    	renderJson(ret);
    }
    
    /**
     * 用户解绑设备
     */
    public void unbundlingDevice(Integer deviceId) {
    	Ret ret = deviceService.unbundlingDevice(getAttr("user"), deviceId);
    	renderJson(ret);
    }
    
    /**
     * 设置设备阈值信息
     */
    public void setThreshold(DeviceThresholdDTO threshold) {
    	Ret ret = deviceService.setThreshold(getAttr("user"), threshold);
    	renderJson(ret);
    }
    
//    @PostMapping("/batch/generation/device")
//    @TokenCheck
//    @ApiOperation(value = "从iot获取设备批量添加", notes = "device")
//    public BaseResponse batchGenerationDevice() {
//        deviceService.batchGenerationDevice();
//        return new BaseResponse();
//    }
//
//    @PostMapping("/find/by/device/paramrter")
//    @TokenCheck
//    @ApiOperation(value = "查询设备参数", notes = "device")
//    public BaseResponse findByDeviceParamrter() {
//        BaseResponse baseResponse = new BaseResponse();
//        baseResponse.setData(deviceService.findByDeviceParamrter());
//        return baseResponse;
//    }
//
//    /**
//     * create by liling 2020-10-19 16:56
//     *
//     * @param getDeviceListReq
//     * @return
//     */
//    @PostMapping("/device/list")
//    @TokenCheck
//    @ApiOperation(value = "批量查询", notes = "device")
//    public BaseResponse deviceList(@RequestBody @Valid GetDeviceListReq getDeviceListReq) {
//        return new BaseResponse(deviceService.deviceList(getDeviceListReq));
//    }
//
//    @PostMapping("/calculation/threshold")
//    @TokenCheck
//    @ApiOperation(value = "计算阈值", notes = "device")
//    public BaseResponse calculationThreshold(@RequestBody @Valid CalculationThresholdReq calculationThresholdReq) {
//        BaseResponse baseResponse = new BaseResponse();
//        baseResponse.setData(deviceService.calculationThreshold(calculationThresholdReq));
//        return baseResponse;
//    }
//
//    @PostMapping("/save/device/parameters")
//    @TokenCheck
//    @ApiOperation(value = "保存设备参数", notes = "device")
//    public BaseResponse saveDeviceParameters(@RequestBody @Valid SaveDeviceParametersReq saveDeviceParametersReq) {
//        BaseResponse baseResponse = new BaseResponse();
//        deviceService.saveDeviceParameters(saveDeviceParametersReq);
//        return baseResponse;
//    }
//
//    @PostMapping("/add/default/threshold")
//    @TokenCheck
//    @ApiOperation(value = "添加默认阈值", notes = "device")
//    public BaseResponse addDefaultThreshold(@RequestBody @Valid AddDefaultThresholdReq addDefaultThresholdReq) {
//        deviceService.addDefaultThreshold(addDefaultThresholdReq);
//        return new BaseResponse();
//    }
//
////    @PostMapping("/inquire/default/threshold")
////    @TokenCheck
////    @ApiOperation(value = "查询默认阈值", notes = "device")
////    public BaseResponse inquireDefaultThreshold(@RequestBody @Valid AddDefaultThresholdReq addDefaultThresholdReq) {
////        deviceService.inquireDefaultThreshold(addDefaultThresholdReq);
////        return new BaseResponse();
////    }
//
//    @PostMapping("/set/default/threshold")
//    @TokenCheck
//    @ApiOperation(value = "设置默认阈值", notes = "device")
//    public BaseResponse setDefaultThreshold(@RequestBody @Valid SetDefaultThresholdReq setDefaultThresholdReq) {
//        deviceService.setDefaultThreshold(setDefaultThresholdReq);
//        return new BaseResponse();
//    }
//
//    @PostMapping("/find/by/device/type")
//    @TokenCheck
//    @ApiOperation(value = "根据设备类型获取默认阈值", notes = "device")
//    public BaseResponse findByDeviceType(@RequestBody @Valid FindByDeviceTypeReq findByDeviceTypeReq) {
//        BaseResponse baseResponse = new BaseResponse();
//        baseResponse.setData(deviceService.findByDeviceType(findByDeviceTypeReq));
//        return baseResponse;
//    }
//
//    @PostMapping("/find/by/project/id")
//    @TokenCheck
//    @ApiOperation(value = "根据项目查询设备", notes = "device")
//    public BaseResponse findByProjectId(@RequestBody @Valid FindByProjectIdReq findByProjectIdReq) {
//        BaseResponse baseResponse = new BaseResponse();
//        baseResponse.setData(deviceService.findByProjectId(findByProjectIdReq));
//        return baseResponse;
//    }
//
//    @PostMapping("/find/by/scene/id")
//    @TokenCheck
//    @ApiOperation(value = "根据场景查询设备", notes = "device")
//    public BaseResponse findBySceneId(@RequestBody @Valid FindBySceneIdReq findBySceneIdReq) {
//        BaseResponse baseResponse = new BaseResponse();
//        baseResponse.setData(deviceService.findBySceneId(findBySceneIdReq));
//        return baseResponse;
//    }
//
//    @PostMapping("/device/open/and/close")
//    @TokenCheck
//    @ApiOperation(value = "设备开合闸", notes = "device")
//    public BaseResponse deviceOpenAndClose(@RequestBody @Valid DeviceOpenAndCloseReq deviceOpenAndCloseReq) {
//        deviceService.deviceOpenAndClose(deviceOpenAndCloseReq);
//        return new BaseResponse();
//    }
//
//    @PostMapping("/modify/device/switch")
//    @ApiOperation(value = "修改设备开合闸状态", notes = "device", hidden = true)
//    public BaseResponse modifyDeviceSwitch(@RequestBody @Valid ModifyDeviceSwitchReq modifyDeviceSwitchReq) {
//        deviceService.modifyDeviceSwitch(modifyDeviceSwitchReq);
//        return new BaseResponse();
//    }
//
//    @PostMapping("/list/by/projects")
//    @TokenCheck
//    @ApiOperation(value = "根据项目id列表查询报警设备", notes = "device", hidden = true)
//    public BaseResponse listByProjectIds(@RequestBody @Valid GetDeviceListByProjectIdsReq getDeviceListByProjectIdsReq) {
//        return new BaseResponse(deviceService.listByProjectIds(getDeviceListByProjectIdsReq));
//    }
//
//    @PostMapping("/realtime/data")
//    @TokenCheck
//    @ApiOperation(value = "查询设备实时数据", notes = "device")
//    public BaseResponse realtimeData(@RequestBody @Valid GetRealtimeDataReq getRealtimeDataReq) {
//        return new BaseResponse(deviceService.realtimeData(getRealtimeDataReq));
//    }
//
//    @PostMapping("/project/group")
//    @TokenCheck
//    @ApiOperation(value = "项目设备统计数据", notes = "device")
//    public BaseResponse projectDevice() {
//        return new BaseResponse(deviceService.allGroupByProject());
//    }
//
//
//    @PostMapping("/history/data")
//    @TokenCheck
//    @ApiOperation(value = "历史数据信息", notes = "device")
//    public BaseResponse historyData(@RequestBody @Valid GetHistoryDataReq getHistoryDataReq) {
//        return new BaseResponse(deviceLogService.historyData(getHistoryDataReq));
//    }
//
//    @PostMapping("/history/power")
//    @TokenCheck
//    @ApiOperation(value = "历史电量数据信息", notes = "device")
//    public BaseResponse historyPower(@RequestBody @Valid GetHistoryPowerDataReq getHistoryPowerDataReq) {
//        return new BaseResponse(deviceLogService.historyPower(getHistoryPowerDataReq));
//    }
//
//    @PostMapping("/history/compare/power")
//    @TokenCheck
//    @ApiOperation(value = "历史电量数据对比信息", notes = "device")
//    public BaseResponse powerCompare(@RequestBody @Valid GetPowerCompareReq getPowerCompareReq) {
//        return new BaseResponse(deviceLogService.powerCompare(getPowerCompareReq));
//    }
//
//    @PostMapping("/history/time/type")
//    @TokenCheck
//    @ApiOperation(value = "历史数据查询时间类型", notes = "device")
//    public BaseResponse historyTimeType() {
//        return new BaseResponse(deviceLogService.timeType());
//    }
//
//    @PostMapping("/history/data/type")
//    @TokenCheck
//    @ApiOperation(value = "历史数据查询数据类型", notes = "device")
//    public BaseResponse historyDataType() {
//        return new BaseResponse(deviceLogService.dataType());
//    }
//
//    @PostMapping("/compare/power/time/type")
//    @TokenCheck
//    @ApiOperation(value = "电量对比时间类型", notes = "device")
//    public BaseResponse comparePowerType() {
//        return new BaseResponse(deviceLogService.comparePowerType());
//    }
//
//    @PostMapping("/get/devices/that/are/about/to/expire")
//    @TokenCheck
//    @ApiOperation(value = "查询订单待续费列表", notes = "device")
//    public BaseResponse getDevicesThatAreAboutToExpire() {
//        return new BaseResponse(deviceService.getDevicesThatAreAboutToExpire());
//    }
//
//    @PostMapping("/device/order/detail")
//    @TokenCheck
//    @ApiOperation(value = "订单详情", notes = "device")
//    public BaseResponse deviceOrderDetail(@RequestBody @Valid DeviceOrderDetailReq deviceOrderDetailReq) {
//        return new BaseResponse(deviceService.deviceOrderDetail(deviceOrderDetailReq));
//    }
//
//
//    @PostMapping("/update/device/power")
//    @ApiOperation(value = "更新电量", notes = "device", hidden = true)
//    public BaseResponse updatePower() {
//        deviceLogService.updatePower();
//        return new BaseResponse();
//    }
//
//    @PostMapping("/power/statistics")
//    @TokenCheck
//    @ApiOperation(value = "项目电量统计列表", notes = "device")
//    public BaseResponse powerStatistics() {
//        return new BaseResponse(deviceLogService.powerStatistics());
//    }
//
//    @PostMapping("/device/power/statistics")
//    @TokenCheck
//    @ApiOperation(value = "项目电量统计", notes = "device")
//    public BaseResponse devicePowerStatistics() {
//        return new BaseResponse(deviceLogService.devicePowerStatistics());
//    }
//
//    @PostMapping("/get/device/by/project/id/and/status")
//    @TokenCheck
//    @ApiOperation(value = "根据状态查询设备", notes = "device")
//    public BaseResponse getDeviceByProjectIdAndStatus(@RequestBody @Valid GetDeviceByProjectIdAndStatusReq getDeviceByProjectIdAndStatusReq) {
//        return new BaseResponse(deviceService.getDeviceByProjectIdAndStatus(getDeviceByProjectIdAndStatusReq));
//    }
//
//    @PostMapping("/report")
//    @TokenCheck
//    @ApiOperation(value = "周报月报", notes = "device")
//    public BaseResponse report(@RequestBody @Valid GetUserReportReq getUserReportReq) {
//        return new BaseResponse(deviceAlarmLogService.report(getUserReportReq));
//    }
//
//    @PostMapping("/device/statistics")
//    @TokenCheck
//    @ApiOperation(value = "用户设备在线离线数量统计", notes = "device")
//    public BaseResponse deviceStatistics() {
//        return new BaseResponse(deviceService.deviceStatistics());
//    }
//
//    @PostMapping("/get/device/list/by/device/ids")
//    @TokenCheck
//    @ApiOperation(value = "根据设备id查询设备", notes = "device")
//    public BaseResponse getDeviceListByDeviceIds(@RequestBody @Valid GetDeviceListByDeviceIdsReq getDeviceListByDeviceIdsReq) {
//        return new BaseResponse(deviceService.getDeviceListByDeviceIds(getDeviceListByDeviceIdsReq));
//    }
//
//    @PostMapping("/batch/edit/service/expire/date")
//    @TokenCheck
//    @ApiOperation(value = "批量更新设备到期时长", notes = "device")
//    public BaseResponse batchEditServiceExpireDate(@RequestBody @Valid BatchEditServiceExpireDateReq batchEditServiceExpireDateReq) {
//        deviceService.batchEditServiceExpireDate(batchEditServiceExpireDateReq);
//        return new BaseResponse();
//    }
//
//    @PostMapping("/device/deactivate/list")
//    @TokenCheck
//    @ApiOperation(value = "订单停用列表", notes = "device")
//    public BaseResponse deviceDeactivateList() {
//        return new BaseResponse(deviceService.deviceDeactivateList());
//    }
//
//    @PostMapping("/deactivate/device")
//    @ApiOperation(value = "设备停用", notes = "device")
//    public BaseResponse deactivateDevice(@RequestBody @Valid DeactivateDeviceReq deactivateDeviceReq) {
//        deviceService.deactivateDevice(deactivateDeviceReq);
//        return new BaseResponse();
//    }
//
//    @PostMapping("/query/devices/that/are/about/toExpire")
//    @ApiOperation(value = "查询快到期设备", notes = "device")
//    public BaseResponse queryDevicesThatAreAboutToExpire() {
//        return new BaseResponse(deviceService.queryDevicesThatAreAboutToExpire());
//    }
//
//    @TokenCheck
//    @PostMapping("/query/earliest/device")
//    @ApiOperation(value = "查询用户最早的设备", notes = "device")
//    public BaseResponse queryEarliestDevice() {
//        return new BaseResponse(deviceService.queryEarliestDevice());
//    }
}
